using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spear : Gun
{
    protected override void Shoot()
    {
        direction = (mousePos - new Vector2(transform.position.x, transform.position.y)).normalized;
        transform.right = direction;

        if (timer != 0)
        {
            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                timer = 0;
            }
        }

        if (Input.GetButton("Fire1"))
        {
            /*if (Physics2D.OverlapCircle(new Vector2(player.transform.position.x, player.transform.position.y + 0.35f),
                1, LayerMask.GetMask("Enemy")))
            {
                if (Input.GetButtonDown("Fire1")) { player.GetComponent<PlayerCon>().Knife(direction); }
            }
            else*/
            if (timer == 0 && player.GetComponent<PlayerCon>().parameterPlayer.NowMP - MP_cost >= 0)
            {
                timer = interval;
                if (isCopy == true)
                {
                    if (player.GetComponent<PlayerCon>().parameterPlayer.NowMP - 2 * MP_cost >= 0)
                        Invoke("fire", 0.15f);
                }
                else
                {
                    fire();
                }
            }
        }
    }
    protected override void fire()
    {
        player.GetComponent<PlayerCon>().parameterPlayer.NowMP -= MP_cost;
        anim.SetTrigger("shoot");
        GameObject bullet = ObjectPool.Instance.GetObject(bulletPrefab);
        bullet.transform.position = muzzlePos.position;
        bullet.transform.right = direction;
        player.GetComponent<Rigidbody2D>().velocity += direction*10;
        player.GetComponent<PlayerCon>().timer = 0.05f;
    }
}
